cmake_minimum_required(VERSION 3.1)

# AresDing 在这里设置otapp当前的编译的架构是arm32, arm64, x64...
# set(BUILD_ARCH "arm32")

if(BUILD_ARCH STREQUAL "arm32")
    # AresDing arm32编译设置交叉编译工具链
    message("Build Arch is ARM32")
    set(CMAKE_C_COMPILER "arm-none-linux-gnueabi-gcc")
    set(CMAKE_CXX_COMPILER "arm-none-linux-gnueabi-g++")
elseif(BUILD_ARCH STREQUAL "arm64")
    # AresDing arm64编译设置交叉编译工具链
    message("Build Arch is ARM64")
    set(CMAKE_C_COMPILER "aarch64-linux-gnu-gcc")
    set(CMAKE_CXX_COMPILER "aarch64-linux-gnu-g++")
else()
    # AresDing 默认是x64
    message("Build Arch is X64")
endif()

option(RUN_PROD "Prod?" OFF)

set(project_name oatpp-website) ## rename your project here

project(${project_name})

set(CMAKE_CXX_STANDARD 11)

add_library(${project_name}-lib
        src/AppComponent.hpp
        src/SitePath.hpp
        src/controller/StaticController.hpp
        src/StaticFileManager.cpp
        src/StaticFileManager.hpp
        src/FilesIndex.cpp
        src/FilesIndex.hpp
        src/dto/MyDTOs.hpp
        src/utils/src/CommUtils.cpp
        src/utils/inc/CommUtils.hpp
#         src/Sitemap.cpp
#         src/Sitemap.hpp
)

## link libs
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../_install")
find_package(oatpp              1.3.0 REQUIRED)

set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../_install")
find_package(oatpp-openssl      1.3.0 REQUIRED)

set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../_install")
find_package(oatpp-zlib         1.3.0 REQUIRED)

# AresDing arm32/arm64/x64平台设置ZLIB安装路径
if(BUILD_ARCH STREQUAL "arm32")
    set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../oatpp-zlib/zlib_arm32")
elseif(BUILD_ARCH STREQUAL "arm64")
    set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../oatpp-zlib/zlib_arm64")
else()
    # 电脑本地应该有安装, 不需要设置;
endif()
find_package(ZLIB)

include(FindPkgConfig) # <-- include pkg-config needed by FindLibreSSL.cmake script
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") # <-- use FindLibreSSL.cmake in /cmake folder

# AresDing arm32/arm64/x64平台设置OpenSSL安装路径
if(BUILD_ARCH STREQUAL "arm32")
    set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../oatpp-openssl/openssl_arm32")
elseif(BUILD_ARCH STREQUAL "arm64")
    set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../oatpp-openssl/openssl_arm64")
else()
    set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../oatpp-openssl/openssl_x64")
endif()
find_package(OpenSSL 1.1 REQUIRED)

target_link_libraries(${project_name}-lib
        PUBLIC oatpp::oatpp
        PUBLIC oatpp::oatpp-test
        PUBLIC oatpp::oatpp-openssl
        PUBLIC oatpp::oatpp-zlib
        PUBLIC ZLIB::ZLIB
        PUBLIC OpenSSL::SSL
        PUBLIC OpenSSL::Crypto
        PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../_install/lib/libjsoncpp.so    # 直接指定libjsoncpp.so吧
        PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../_install/lib/libuuid.so 
)

# target_include_directories(${project_name}-lib
#         PUBLIC /usr/local/include
# )
# link_directories(/usr/local/lib)

target_include_directories(${project_name}-lib PUBLIC src)

target_include_directories(${project_name}-lib PUBLIC src/utils/inc)

target_include_directories(${project_name}-lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../_install/include)  # 编译libjsoncpp 直接指定头文件路径

add_definitions(
        -DSTATIC_RES_PATH="${CMAKE_CURRENT_LIST_DIR}/res/dist"
)

if(RUN_PROD)
    add_definitions(-DOATPP_TARGET_APP)
endif()

## add executables

add_executable(${project_name}-exe
        src/App.cpp
)

target_link_libraries(${project_name}-exe ${project_name}-lib)
add_dependencies(${project_name}-exe ${project_name}-lib)

# add_executable(${project_name}-test
#         test/tests.cpp
# )
# target_link_libraries(${project_name}-test ${project_name}-lib)
# add_dependencies(${project_name}-test ${project_name}-lib)
